<?php
/*
 * Summary : Created By Avik on 11th April,2010
 * Version : 1.0
 * Contents: Class to fetch All Data
 * Chnage on 16th April: Category to Theme.
 */

//#########INCLUDE FILES########

include_once 'db-config.php';
include_once 'error.php';

//##############################


	class clsFetchData
	{
		/*
		 * Fetch Data method fetches all the data depending on is_approved input and return as an array
		 */
		public function FetchDataToArray($category,$cityName)
		{
			$arrDataBind = array();
			$count = 0;
			$selectQuery ="SELECT * FROM tbl_globaltodo_listings WHERE category='$category' AND city='$cityName'";
			$run = mysql_query($selectQuery);
			while ($data = mysql_fetch_array($run))
			{
				$arrDataBind[$count]['id'] = $data['unique_id'];
				$arrDataBind[$count]['sl_no'] = stripslashes($data['id']);
				$arrDataBind[$count]['city'] = stripslashes($data['city']);
				$arrDataBind[$count]['theme'] = stripslashes($data['category']);
				$arrDataBind[$count]['business_title'] = stripslashes($data['business_title']);
				$arrDataBind[$count]['business_desc'] = stripslashes($data['business_desc']);
				$arrDataBind[$count]['business_summary'] = stripslashes($data['business_summary']);
				$arrDataBind[$count]['phone_number'] = stripslashes($data['phone_number']);
				$arrDataBind[$count]['street_address'] = stripslashes($data['street_address']);
				$arrDataBind[$count]['email_address'] = $data['email_address'];
				$arrDataBind[$count]['website_address'] = $data['website_address'];
				$arrDataBind[$count]['website_url'] = $data['website_address'];
				$arrDataBind[$count]['audio_url'] = $data['audio_url'];
				$arrDataBind[$count]['video_url'] = $data['video_url'];
				$arrDataBind[$count]['sales_rep'] = stripslashes($data['sales_rep']);
				$arrDataBind[$count]['state'] = stripslashes($data['state']);
				$arrDataBind[$count]['zipcode'] = $data['zipcode'];
				$arrDataBind[$count]['business_logo'] = $data['business_logo'];
				$arrDataBind[$count]['image_1'] = $data['image_1'];
				$arrDataBind[$count]['image_2'] = $data['image_2'];
				$arrDataBind[$count]['image_3'] = $data['image_3'];
				$arrDataBind[$count]['image_4'] = $data['image_4'];
				$arrDataBind[$count]['is_approved'] = $data['is_approved'];
				$arrDataBind[$count]['tollfree_number'] = $data['tollfree_number'];
				$arrDataBind[$count]['fax_number'] = $data['fax_number'];
				$arrDataBind[$count]['barcode_image'] = $data['barcode_image'];
				$count ++;
			}
			return $arrDataBind;
		}
		
		
		
		public function fetchDataAsPerKeyWord($cityName, $searchKeyword)
		{
			$arrDataBind = array();
			$count = 0;
			$selectQuery ="SELECT * FROM tbl_globaltodo_listings WHERE city='$cityName' AND ((business_title LIKE '%$searchKeyword%') OR (business_desc LIKE '%$searchKeyword%')";
			$run = mysql_query($selectQuery);
			while ($data = mysql_fetch_array($run))
			{
				$arrDataBind[$count]['id'] = $data['unique_id'];
				$arrDataBind[$count]['sl_no'] = stripslashes($data['id']);
				$arrDataBind[$count]['city'] = stripslashes($data['city']);
				$arrDataBind[$count]['theme'] = stripslashes($data['category']);
				$arrDataBind[$count]['business_title'] = stripslashes($data['business_title']);
				$arrDataBind[$count]['business_desc'] = stripslashes($data['business_desc']);
				$arrDataBind[$count]['business_summary'] = stripslashes($data['business_summary']);
				$arrDataBind[$count]['phone_number'] = stripslashes($data['phone_number']);
				$arrDataBind[$count]['street_address'] = stripslashes($data['street_address']);
				$arrDataBind[$count]['email_address'] = $data['email_address'];
				$arrDataBind[$count]['website_address'] = $data['website_address'];
				$arrDataBind[$count]['website_url'] = $data['website_address'];
				$arrDataBind[$count]['audio_url'] = $data['audio_url'];
				$arrDataBind[$count]['video_url'] = $data['video_url'];
				$arrDataBind[$count]['sales_rep'] = stripslashes($data['sales_rep']);
				$arrDataBind[$count]['state'] = stripslashes($data['state']);
				$arrDataBind[$count]['zipcode'] = $data['zipcode'];
				$arrDataBind[$count]['business_logo'] = $data['business_logo'];
				$arrDataBind[$count]['image_1'] = $data['image_1'];
				$arrDataBind[$count]['image_2'] = $data['image_2'];
				$arrDataBind[$count]['image_3'] = $data['image_3'];
				$arrDataBind[$count]['image_4'] = $data['image_4'];
				$arrDataBind[$count]['is_approved'] = $data['is_approved'];
				$arrDataBind[$count]['tollfree_number'] = $data['tollfree_number'];
				$arrDataBind[$count]['fax_number'] = $data['fax_number'];
				$arrDataBind[$count]['barcode_image'] = $data['barcode_image'];
				$count ++;
			}
			return $arrDataBind;
		}
		
		
		
	public function FetchDataToArrayForParticularId($unique_id)
		{
			$arrDataBind = array();
			$count = 0;
			$selectQuery ="SELECT * FROM tbl_globaltodo_listings WHERE id=$unique_id";
			$run = mysql_query($selectQuery);
			while ($data = mysql_fetch_array($run))
			{
				$arrDataBind[$count]['id'] = $data['unique_id'];
				$arrDataBind[$count]['sl_no'] = stripslashes($data['id']);
				$arrDataBind[$count]['city'] = stripslashes($data['city']);
				$arrDataBind[$count]['theme'] = stripslashes($data['category']);
				$arrDataBind[$count]['business_title'] = stripslashes($data['business_title']);
				$arrDataBind[$count]['business_desc'] = stripslashes($data['business_desc']);
				$arrDataBind[$count]['business_summary'] = stripslashes($data['business_summary']);
				$arrDataBind[$count]['phone_number'] = stripslashes($data['phone_number']);
				$arrDataBind[$count]['street_address'] = stripslashes($data['street_address']);
				$arrDataBind[$count]['email_address'] = $data['email_address'];
				$arrDataBind[$count]['website_address'] = $data['website_address'];
				$arrDataBind[$count]['audio_url'] = $data['audio_url'];
				$arrDataBind[$count]['video_url'] = $data['video_url'];
				$arrDataBind[$count]['sales_rep'] = stripslashes($data['sales_rep']);
				$arrDataBind[$count]['state'] = stripslashes($data['state']);
				$arrDataBind[$count]['zipcode'] = $data['zipcode'];
				$arrDataBind[$count]['business_logo'] = $data['business_logo'];
				$arrDataBind[$count]['image_1'] = $data['image_1'];
				$arrDataBind[$count]['image_2'] = $data['image_2'];
				$arrDataBind[$count]['image_3'] = $data['image_3'];
				$arrDataBind[$count]['image_4'] = $data['image_4'];
				$arrDataBind[$count]['is_approved'] = $data['is_approved'];
				$arrDataBind[$count]['tollfree_number'] = $data['tollfree_number'];
				$arrDataBind[$count]['fax_number'] = $data['fax_number'];
				$arrDataBind[$count]['barcode_image'] = $data['barcode_image'];
				$count ++;
			}
			return $arrDataBind;
		}
		
		/*
		 * FETCH ALL CATEGORIES FROM DATABASE
		 */
		
		public function FetchAllCategories()
		{
			$arrDataBind = array();
			$count = 0;
			
			$sql = "SELECT `id`, `name` FROM tbl_category_listing ORDER BY `name`";
			$run = mysql_query($sql);
			while ($data = mysql_fetch_array($run))
			{
				$arrDataBind[$count]['sl_no'] = $data['id'];
				$arrDataBind[$count]['name'] = stripslashes($data['name']);
				$count ++;
			}
			
			return $arrDataBind;
		}
	}  






?>